<?
include "include/config.php";

$location='setari';

if (!isset($_SESSION['_user']))  {
    header ("location: login.php");
}
if ($_SESSION['_level'] != 0) {
    header ("location: index.php");
}
////modificare nume locatie
if ($_POST['hidden_cat'] == 1)  {
    mysql_query ("update locatii set name=UPPER('" . $_POST['locatie_mod'] . "') where id='" . $_GET['id'] . "' ");
}

if ($_GET['id'] == '')
      $parent=0;  
else
    $parent=$_GET['id'];    
  
    
if ($_POST['locatie'] != '') {
    mysql_query ("insert into locatii(name,id_parent) values(UPPER('" . $_POST['locatie'] . "'),'" . $parent . "')");
}
   


///display tabel
if ($_GET['id'] != '') {
    if ($_GET['id_p'] != '')
        $parent=$_GET['id_p'];
}
$query_tree=mysql_query("select * from locatii where id_parent = '" . $parent . "' ORDER BY name ASC ");  
////display path

$lvl=0;

if ($parent != 0)  {
    while ($parent != 0)   {
        $query_path    = mysql_query("select * from locatii where id = '" . $parent . "'  ORDER BY name ASC ");
         $part          =mysql_fetch_array($query_path);
        $parents_nume[]=$part['name'];
        $parents_id[]  =$part['id'];
        $parent        =$part['id_parent'];
        $lvl++;
    }
}

 
switch ($lvl) {
    case 0:   $locatie="ZONA 1";  break;
    case 1:   $locatie="ZONA 2"; break;
    case 2:   $locatie="ZONA 2"; break;
    default:  $locatie='';    break;
}
include ('include/head.php');



?>

<div id = "container">
    <?
    include "include/meniu.php";
    ?>

    <div id = "submenu">
        <div>
            <div>
                <ul>
                    <li id = "off2"><a href = "locatii.php">Locatii</a></li>
                    <li><a href = "parteneri.php">Parteneri</a></li>
                </ul>
            </div>
        </div>
    </div>

    <div id = "content">
        <div id = "mid">
            <div>
                <form action = "locatii.php?id=<? if ($_GET['id_p']!='') echo $_GET['id_p']; else echo $_GET['id'];?>"
                      method = "post" enctype = "multipart/form-data">
                    <h2>Adaugati &nbsp;<?=$locatie?></h2>

                    <label>Nume</label>

                    <? if ($lvl<3) { ?> 
                    <input name = "locatie" id = "locatie" type = "text" class = "tf b"/>
                        
                    <br class = "clear"/>
                    <br class = "clear"/>
                    <label>&nbsp;</label>
                    <input type = "submit" name = "adauga" value = "Adauga" class = "ok"/>
                    <?}?>
                </form>
            </div>

            <div>
                <br class = "clear"/>

                <div id = "bar">
                    <div>
                        <a href = "locatii.php">Main</a> 
                        <? for ($i=count($parents_nume);$i>0;$i--) { ?>
                        
                        <a href = "locatii.php?id=<?=$parents_id[($i-1)]?>">&nbsp;&nbsp;&raquo;&nbsp;<?=$parents_nume[($i-1)]?></a>
                        <? }?>
                    </div>
                </div>

                <div>
                    <div class = "cell bbb ac">Nume </div>
                    <br class = "clear"/>

                    <? $j=0; while ($result=mysql_fetch_array($query_tree)) {   
                        if ($j%2==0) $class='cell__'; else  $class='cell_';
                    ?> 

                    <div class="<?=$class?> bbb fl">                    
                    <? if($lvl<2) { ?><a href = "locatii.php?id=<?=$result['id']?>"><?}?><strong><?=htmlentities($result['name'])?></strong> </a>
                    </div>

                    <div class='<?=$class?> '>
                        <a href = "modifica_loc.php?id=<?=$result['id']?>">
                            <img src = "imagini/modifica.gif" />
                        </a>
                    </div>

                    <div class='<?=$class?> '>
                        <a href = "sterge_loc.php?id=<?=$result['id']?>" onclick = "return delete_confirm('Sunteri siguri ca vreti sa stergeti locatia <?=$result['name']?>!!!')">
                            <img src = "imagini/sterge.gif" />
                        </a>
                    </div>

                    <br class = "clear"/>

                   <? $j++; } ?>
                </div>
            </div>
        </div>
    </div>
</div>

</div>

<?
include ('include/footer.php');
?>